<?php
declare (strict_types = 1);

namespace app\home\controller;

use app\common\controller\Frontend;
use think\facade\Db;
use think\facade\View;


class Album extends Frontend
{
    public function initialize()
    {
        parent::initialize();
    }


    // 首页控制器
    public function index() {
        global $userinfo;
        // 取seo信息

        // 取专辑列表

        $count=DB::name('album')->where('status',1)->count();

        $page=new  \think\Page($count,20);
        $show=$page->show();
        $search_order =request()->param('search_order');
        if (!$search_order) {
            $search_order = 1;
        }

        $order = 'a.zhiding desc,a.tuijian desc,a.id desc';
        if ($search_order == 3) {
            # 文档数量
            $order = 'count desc, a.id desc';
        } elseif ($search_order == 2) {
            # 时间
            $order = 'a.id desc';
        }

        $sql = 'select a.*, (select count(1) from wk_doc_con where zjid = a.id) as count from wk_album as a where a.status = 1 order by ' . $order . ' limit ' . $page->firstRow.','.$page->listRows;
        $zjlist=Db::query($sql);

        //$zjlist=$mod->where($where)->order($order)->limit($page->firstRow.','.$page->listRows)->select();

        View::assign('search_order',$search_order);
        View::assign('zjlist',$zjlist);
        View::assign('page',$show);
        return \view();

    }
    // 专辑文档页面
    public function zjinfo() {
        // 取seo信息
        $id = request()->param('id')?request()->param('id'):0;

        // 获取前台get过来的专辑id
//        $id=request()->param('id');

        // 获取当前专辑信息
        $zjinfo = Db::name('album')->find($id);

        //获取专辑下文档
        $mod=Db::name('doc_con');
        $where[]=array('zjid','=',$id) ;
        $where[]=array('status','>',0) ;
        $count=$mod->where($where)->count();
        $page = new  \think\Page($count,18);
        $show = $page->show();
        $zjdoc = $mod->where($where)->limit($page->firstRow,$page->listRows)->select();

        // 获取专辑下文档浏览总数
        $zjhits = $mod->where($where)->sum('hits');

        // print_r($zjdoc);
//        View::assign('id',$id);
        View::assign('zjinfo',$zjinfo);
        View::assign('zjdoc',$zjdoc);
        View::assign('page',$show);
        View::assign('zjhits',$zjhits);
        return \view();

    }
}